﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：YS_QT_GONGZUORGL实体层次
//********************************************************************************//

#region Entity

using System;
using System.Data;
using Entity;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class YS_QT_GONGZUORGL
    {
        private decimal? m_dec_i_day;

        private decimal? m_dec_i_month;

        private decimal? m_dec_i_sfgzr;

        private decimal? m_dec_i_weekday;

        private decimal? m_dec_i_year;

        private decimal m_dec_id;

        private DateTime? m_DT_d_date;

        private string m_str_s_beiyong;

        /// <summary>
        ///     主键
        /// </summary>
        public decimal ID
        {
            get { return m_dec_id; }
            set { m_dec_id = value; }
        }

        /// <summary>
        ///     时间
        /// </summary>
        public DateTime? D_DATE
        {
            get { return m_DT_d_date; }
            set { m_DT_d_date = value; }
        }

        /// <summary>
        ///     星期几( 1 周日，2 周一，3 周二)
        /// </summary>
        public decimal? I_WEEKDAY
        {
            get { return m_dec_i_weekday; }
            set { m_dec_i_weekday = value; }
        }

        /// <summary>
        ///     是否工作日（0 非工作日，1 工作日）
        /// </summary>
        public decimal? I_SFGZR
        {
            get { return m_dec_i_sfgzr; }
            set { m_dec_i_sfgzr = value; }
        }

        /// <summary>
        ///     备用
        /// </summary>
        public string S_BEIYONG
        {
            get { return m_str_s_beiyong; }
            set { m_str_s_beiyong = value; }
        }

        /// <summary>
        ///     年
        /// </summary>
        public decimal? I_YEAR
        {
            get { return m_dec_i_year; }
            set { m_dec_i_year = value; }
        }

        /// <summary>
        ///     月
        /// </summary>
        public decimal? I_MONTH
        {
            get { return m_dec_i_month; }
            set { m_dec_i_month = value; }
        }

        /// <summary>
        ///     日
        /// </summary>
        public decimal? I_DAY
        {
            get { return m_dec_i_day; }
            set { m_dec_i_day = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL.Access
{
    //using System.Data.OracleClient;

    public class YS_QT_GONGZUORGLProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public YS_QT_GONGZUORGLProcess()
        {
            conn = ConfigHelper.PlatformConnString;
        }

        #endregion

        #region public

        /// <summary>
        ///     根据YS_QT_GONGZUORGL实体添加或者修改YS_QT_GONGZUORGL信息
        /// </summary>
        public bool InsertOrUpdate(YS_QT_GONGZUORGL YS_QT_GONGZUORGL, OracleTransaction Transaction)
        {
            if (YS_QT_GONGZUORGL.ID == 0)
                InsertYS_QT_GONGZUORGL(YS_QT_GONGZUORGL, Transaction);
            else
                UpdateYS_QT_GONGZUORGL(YS_QT_GONGZUORGL, Transaction);
            return YS_QT_GONGZUORGL.ID == 0 ? false : true;
        }

        /// <summary>
        ///     根据YS_QT_GONGZUORGL实体添加或修改YS_QT_GONGZUORGL信息
        /// </summary>
        public bool InsertOrUpdate(YS_QT_GONGZUORGL YS_QT_GONGZUORGL)
        {
            return InsertOrUpdate(YS_QT_GONGZUORGL, null);
        }


        /// <summary>
        ///     根据YS_QT_GONGZUORGL主键删除YS_QT_GONGZUORGL信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteYS_QT_GONGZUORGL(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_DelYS_QT_GONGZUORGL";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据YS_QT_GONGZUORGL主键删除YS_QT_GONGZUORGL信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteYS_QT_GONGZUORGL(decimal ID)
        {
            return DeleteYS_QT_GONGZUORGL(ID, null);
        }

        /// <summary>
        ///     根据条件删除YS_QT_GONGZUORGL信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteYS_QT_GONGZUORGLsDynamic(string WhereClause, OracleTransaction Transaction)
        {
            var spName = "CS_DelYS_QT_GONGZUORGLsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据条件删除YS_QT_GONGZUORGL信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteYS_QT_GONGZUORGLsDynamic(string WhereClause)
        {
            return DeleteYS_QT_GONGZUORGLsDynamic(WhereClause, null);
        }

        /// <summary>
        ///     根据YS_QT_GONGZUORGL主键选择YS_QT_GONGZUORGL信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_QT_GONGZUORGL信息</returns>
        public YS_QT_GONGZUORGL SelectYS_QT_GONGZUORGL(decimal ID, OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_QT_GONGZUORGL";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                var YS_QT_GONGZUORGL = PopulateYS_QT_GONGZUORGL(rd);
                rd.Close();
                return YS_QT_GONGZUORGL;
            }
            return null;
        }

        /// <summary>
        ///     根据YS_QT_GONGZUORGL主键选择YS_QT_GONGZUORGL信息
        /// </summary>
        /// <returns>YS_QT_GONGZUORGL信息</returns>
        public YS_QT_GONGZUORGL SelectYS_QT_GONGZUORGL(decimal ID)
        {
            return SelectYS_QT_GONGZUORGL(ID, null);
        }

        /// <summary>
        ///     选择所有YS_QT_GONGZUORGL信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有YS_QT_GONGZUORGL信息</returns>
        public DataTable SelectYS_QT_GONGZUORGLsAll(OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_QT_GONGZUORGLsAll";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }

        /// <summary>
        ///     选择所有YS_QT_GONGZUORGL信息
        /// </summary>
        /// <returns>所有YS_QT_GONGZUORGL信息</returns>
        public DataTable SelectYS_QT_GONGZUORGLsAll()
        {
            return SelectYS_QT_GONGZUORGLsAll(null);
        }

        /// <summary>
        ///     根据条件选择YS_QT_GONGZUORGL信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_QT_GONGZUORGL信息</returns>
        public DataTable SelectYS_QT_GONGZUORGLsDynamic(string WhereClause, string OrderByExpression,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_QT_GONGZUORGLsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择YS_QT_GONGZUORGL信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>YS_QT_GONGZUORGL信息</returns>
        public DataTable SelectYS_QT_GONGZUORGLsDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectYS_QT_GONGZUORGLsDynamic(WhereClause, OrderByExpression, null);
        }


        /// <summary>
        ///     根据条件选择YS_QT_GONGZUORGL信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>YS_QT_GONGZUORGL信息</returns>
        public DataTable SelectYS_QT_GONGZUORGLsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize, OracleTransaction Transaction)
        {
            var spName = "CS_SelYS_QT_GONGZUORGLsDynPaged";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择YS_QT_GONGZUORGL信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>YS_QT_GONGZUORGL信息</returns>
        public DataTable SelectYS_QT_GONGZUORGLsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize)
        {
            return SelectYS_QT_GONGZUORGLsDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///     根据条件更新YS_QT_GONGZUORGL字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateYS_QT_GONGZUORGLsDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            var result = 0;
            if (UpdateValue == "" || WhereClause == "")
                return 0;
            var spName = "CS_UpdYS_QT_GONGZUORGLDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///     根据条件更新YS_QT_GONGZUORGL字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateYS_QT_GONGZUORGLsDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateYS_QT_GONGZUORGLsDynamic(UpdateValue, WhereClause, null);
        }

        #endregion

        #region Private

        private int InsertYS_QT_GONGZUORGL(YS_QT_GONGZUORGL YS_QT_GONGZUORGL, OracleTransaction Transaction)
        {
            var spName = "CS_InsYS_QT_GONGZUORGL";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = YS_QT_GONGZUORGL.D_DATE;
            storedParams[1].Value = YS_QT_GONGZUORGL.I_WEEKDAY;
            storedParams[2].Value = YS_QT_GONGZUORGL.I_SFGZR;
            storedParams[3].Value = YS_QT_GONGZUORGL.S_BEIYONG;
            storedParams[4].Value = YS_QT_GONGZUORGL.I_YEAR;
            storedParams[5].Value = YS_QT_GONGZUORGL.I_MONTH;
            storedParams[6].Value = YS_QT_GONGZUORGL.I_DAY;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            YS_QT_GONGZUORGL.ID = Convert.ToInt32(storedParams[7].Value);
            return result;
        }

        private bool UpdateYS_QT_GONGZUORGL(YS_QT_GONGZUORGL YS_QT_GONGZUORGL, OracleTransaction Transaction)
        {
            var spName = "CS_UpdYS_QT_GONGZUORGL";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = YS_QT_GONGZUORGL.D_DATE;
            storedParams[1].Value = YS_QT_GONGZUORGL.I_WEEKDAY;
            storedParams[2].Value = YS_QT_GONGZUORGL.I_SFGZR;
            storedParams[3].Value = YS_QT_GONGZUORGL.S_BEIYONG;
            storedParams[4].Value = YS_QT_GONGZUORGL.I_YEAR;
            storedParams[5].Value = YS_QT_GONGZUORGL.I_MONTH;
            storedParams[6].Value = YS_QT_GONGZUORGL.I_DAY;
            storedParams[7].Value = YS_QT_GONGZUORGL.ID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private YS_QT_GONGZUORGL PopulateYS_QT_GONGZUORGL(IDataReader dr)
        {
            var YS_QT_GONGZUORGL = new YS_QT_GONGZUORGL();
            YS_QT_GONGZUORGL.ID = dr["ID"] == DBNull.Value ? 0 : (decimal) dr["ID"];
            YS_QT_GONGZUORGL.D_DATE = dr["D_DATE"] == DBNull.Value ? null : (DateTime?) dr["D_DATE"];
            YS_QT_GONGZUORGL.I_WEEKDAY = dr["I_WEEKDAY"] == DBNull.Value ? null : (decimal?) dr["I_WEEKDAY"];
            YS_QT_GONGZUORGL.I_SFGZR = dr["I_SFGZR"] == DBNull.Value ? null : (decimal?) dr["I_SFGZR"];
            YS_QT_GONGZUORGL.S_BEIYONG = dr["S_BEIYONG"] == DBNull.Value ? null : (string) dr["S_BEIYONG"];
            YS_QT_GONGZUORGL.I_YEAR = dr["I_YEAR"] == DBNull.Value ? null : (decimal?) dr["I_YEAR"];
            YS_QT_GONGZUORGL.I_MONTH = dr["I_MONTH"] == DBNull.Value ? null : (decimal?) dr["I_MONTH"];
            YS_QT_GONGZUORGL.I_DAY = dr["I_DAY"] == DBNull.Value ? null : (decimal?) dr["I_DAY"];
            return YS_QT_GONGZUORGL;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (var i = 0; i < dt.Rows.Count; i++)
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
        }

        #endregion
    }
}

#endregion